package com.um.springboot.starter.logs;

import cn.hutool.core.util.ArrayUtil;
import com.um.springboot.starter.properties.HshProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 邓南辉
 * 日期 2023/3/4
 * 版权所有 广州优匠科技有限公司
 */
@Component
@Slf4j
public class SqlLog {

    @Autowired
    HshProperties hshProperties;

    public void debug(String tag, String sql, Object... values) {
        if (hshProperties.getConfig().isPrintSqlLog()) {
            sql = (sql + "").trim(); //去掉首尾空白
            sql = sql.replaceAll("(?m)^\\s+", ""); //去掉每行前面空白
            if (ArrayUtil.isEmpty(values) || (values.length == 1 && values[0] == null)) {
                log.info("{}: {}", tag, sql);
            } else {
                log.info("{}: {}, {}", tag, sql, values);
            }
        }
    }
}
